/* Copyright 2007 Sergejs Melderis (sergey.melderis@gmail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
*/
package com.sm.binder;


import java.sql.*;
import java.math.BigDecimal;


/**
 * Base class for different type of getters that retrieve values from
 * ResultSet columns. Each getter retrieves only one value.
 *
 *
 * @author Sergejs Melderis (sergey.melderis@gmail.com)
 */
abstract class ColumnValueGetter {
     protected final int colIndex;

    public ColumnValueGetter(int colIndex) {
        this.colIndex = colIndex;
    }

    public abstract Object getValue(ResultSet rs) throws SQLException;
}


class BigDecimalGetter extends ColumnValueGetter {
    public BigDecimalGetter(int colIndex) {
        super(colIndex);
    }

    public BigDecimal getValue(ResultSet rs) throws SQLException {
        return rs.getBigDecimal(colIndex);
    }
}


class BooleanGetter extends ColumnValueGetter {
    public BooleanGetter(int colIndex) {
        super(colIndex);
    }

    public Boolean getValue(ResultSet rs) throws SQLException {
        return rs.getBoolean(colIndex);
    }
}

class ByteGetter extends ColumnValueGetter {
    public ByteGetter(int colIndex) {
        super(colIndex);
    }

    public Byte getValue(ResultSet rs) throws SQLException {
        return rs.getByte(colIndex);
    }
}

class DateGetter extends ColumnValueGetter {
    public DateGetter(int colIndex) {
        super(colIndex);
    }

    public Date getValue(ResultSet rs) throws SQLException {
        return rs.getDate(colIndex);
    }
}


class DoubleGetter extends ColumnValueGetter {
    public DoubleGetter(int colIndex) {
        super(colIndex);
    }

    public Double getValue(ResultSet rs) throws SQLException {
        return rs.getDouble(colIndex);
    }
}


class FloatGetter extends ColumnValueGetter {
    public FloatGetter(int colIndex) {
        super(colIndex);
    }

    public Float getValue(ResultSet rs) throws SQLException {
        return rs.getFloat(colIndex);
    }
}

class IntegerGetter extends ColumnValueGetter {
    public IntegerGetter(int colIndex) {
        super(colIndex);
    }

    public Integer getValue(ResultSet rs) throws SQLException {
        return rs.getInt(colIndex);
    }
}


class LongGetter extends ColumnValueGetter {
    public LongGetter(int colIndex) {
        super(colIndex);
    }

    public Long getValue(ResultSet rs) throws SQLException {
        return rs.getLong(colIndex);
    }
}


class ShortGetter extends ColumnValueGetter {
    public ShortGetter(int colIndex) {
        super(colIndex);
    }

    public Short getValue(ResultSet rs) throws SQLException {
        return rs.getShort(colIndex);
    }
}


class StringGetter extends ColumnValueGetter {
    public StringGetter(int colIndex) {
        super(colIndex);
    }

    public String getValue(ResultSet rs) throws SQLException {
        return rs.getString(colIndex);
    }
}


class TimeGetter extends ColumnValueGetter {
    public TimeGetter(int colIndex) {
        super(colIndex);
    }

    public Time getValue(ResultSet rs) throws SQLException {
        return rs.getTime(colIndex);
    }
}


class TimestampGetter extends ColumnValueGetter {
    public TimestampGetter(int colIndex) {
        super(colIndex);
    }

    public Timestamp getValue(ResultSet rs) throws SQLException {
        return rs.getTimestamp(colIndex);
    }
}





